package com.tensai.study.java.basic.asynchronous.thread.executor.run;

import com.tensai.study.java.basic.asynchronous.thread.executor.task.CallableTest;
import io.netty.util.concurrent.DefaultThreadFactory;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.*;

/**
 * 线程池，可以通过调用 {@link Executors} 以下静态工厂方法来创建线程池并返回一个 {@link ExecutorService} 对象：
 *
 * @author Tensai
 * @see java.util.concurrent.ThreadPoolExecutor
 * @since java-1.5
 */
@Slf4j
public class ThreadPoolExecutorTest {

	@Test
	public void test() {
		ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 10,
				100, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(5),
				new DefaultThreadFactory("test-"));
		Future<String> future = tpe.submit(new CallableTest());

		try {
			log.info(future.get());
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			tpe.shutdown();
		}
	}
}
